package cn.edu.zafu.bigdata.x.zzzznnn.h;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
    public static void main(String[] args) {
        try {
            DatagramSocket clientSocket = new DatagramSocket();
            InetAddress serverAddress = InetAddress.getByName("同学电脑的IP地址");
            int serverPort = 0000;
            byte[] requestData = new byte[0];
            DatagramPacket requestPacket = new DatagramPacket(requestData, requestData.length, serverAddress, serverPort);
            clientSocket.send(requestPacket);
            byte[] buffer = new byte[1024];
            DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
            clientSocket.receive(receivePacket);
            String receivedTime = new String(receivePacket.getData(), 0, receivePacket.getLength());
            System.out.println("从服务端获取的当前时间：" + receivedTime);
            clientSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
